package com.example.lancooznbk.presenter;

import com.example.lancooznbk.model.api.ReviewProgressApi;
import com.example.lancooznbk.model.result.ReviewProgressEntity;
import com.example.lancooznbk.view.base.IBaseView;
import com.example.lancooznbk.view.base.ILoadDataPresenter;
import com.example.lancooznbk.view.base.ILoadDataView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

/**
 * Created by tangminglong on 17/9/20.
 */

public class ReviewProgressPresenter implements ILoadDataPresenter {
    private ILoadDataView mView;

    public ReviewProgressPresenter(ILoadDataView mView) {
        this.mView = mView;
    }

    @Override
    public void getData(boolean isShowing) {
        if (isShowing) mView.showLoading();
        HttpOnNextListener<ReviewProgressEntity> httpOnNextListener = new HttpOnNextListener<ReviewProgressEntity>() {
            @Override
            public void onNext(ReviewProgressEntity reviewProgressEntity) {
                if ("0".equals(reviewProgressEntity.getError())){
                    mView.loadData(reviewProgressEntity);
                }else {
                    mView.showNetError();
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mView.showNetError();
            }
        } ;

        ReviewProgressApi api = new ReviewProgressApi(httpOnNextListener, (RxAppCompatActivity) mView);
        HttpManager.getInstance().doHttpDeal(api);
    }

    @Override
    public void getMoreData() {

    }
}
